﻿using Microsoft.Owin.Security;
using Sidvall.Security;
using Sidvall.Web.Host;
using System.Threading.Tasks;

namespace Sidvall.LogManager.Web.Host
{
    public class AuthenticationTicketProvider : DefaultAuthenticationTicketProvider
    {
        #region Public Members

        public override async Task<AuthenticationTicket> GetAuthenticationTicketAsync(AuthenticationTicket authenticationTicket, ServerContent serverContent, TokenResponse tokenResponse)
        {
            return await base.GetAuthenticationTicketAsync(authenticationTicket, serverContent, tokenResponse);
        }

        #endregion
        #region Factory Members

        private static readonly object _Mutex = new object();
        private static volatile AuthenticationTicketProvider _Current;
        public static AuthenticationTicketProvider Current
        {
            get
            {
                if (_Current == null)
                {
                    lock (_Mutex)
                    {
                        if (_Current == null)
                        {
                            var item = new AuthenticationTicketProvider();
                            _Current = item;
                        }
                    }
                }
                return _Current;
            }
            set
            {
                lock (_Mutex)
                {
                    _Current = value;
                }
            }
        }

        #endregion
    }
}